home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 112 / EnigmaAmiga112CD.iso / dalla rivista / awnpipe / awnp / awnp-docs / tutorials / tutorial2.rx < prev    next >
Text File  |  1999-10-31  |  4KB  |  173 lines

  1. /*Tutorial 2 for AWNPipe*/
  2.  
  3. call setdefaults()
  4. call buildgui()
  5.  
  6. do while ~eof(ca)
  7. in= readln(ca)
  8. parse var in in1 in2 in3 in4 .
  9. if in1='gadget' then call gadget()
  10. if in1='menu' then call menu()
  11. if in1='close' then call windowclosed()
  12. end
  13.  
  14. exit
  15.  
  16. gadget:
  17. if in2=agegad then age=in3  Close
  18. if in2=sexgad then sex=in3
  19. if in2=knogad then knowledge=in3
  20. if in2=basgad then basic=in3
  21. if in2=aregad then arexx=in3
  22. if in2=cgad then c=in3
  23. if in2=asmgad then asm=in3
  24. /* the return from a string gadget is parsed differently since it can be more
  25. then 1 word. */
  26. if in2=namegad then do
  27. parse var in . . in3
  28. name=in3
  29. end
  30.  
  31. if in2=dongad then do
  32. call printdata()
  33. exit
  34. end
  35.  
  36. if in2=resgad then do
  37. call close(ca)
  38. call setdefaults()
  39. call buildgui()
  40. end
  41.  
  42. if in2=cangad then do
  43. say 'user canceled'
  44. exit
  45. end
  46.  
  47. return
  48.  
  49. windowclosed:
  50. say 'User aborted with CTRL BackSlash or closed window.'
  51. exit
  52. return
  53.  
  54. menu:
  55. /* menu 0 is just informational so can be ignored */
  56.  
  57. if in2=1 then do
  58. if in3=0 then call printdata()
  59. if in3=1 then do
  60. if in4=0 then say 'name' name 'age' age 'sex' sex
  61. if in4=1 then say 'knowledge' knowledge 'basic' basic 'arexx' arexx 'c' c 'asm' asm
  62. end
  63. end
  64. return
  65.  
  66.  
  67. setdefaults:
  68. name='unset'
  69. age=30
  70. sex=0
  71. knowledge=0
  72. basic=0
  73. c=0
  74. asm=0
  75. arexx=0
  76. return
  77.  
  78. buildgui:
  79. /* Open pipe 'tut2' with GUI creation option '/xc' */
  80. call open(ca,"awnpipe:tut2/xc")
  81.  
  82. /* define the window */
  83.  
  84. /* The first line oF every GUI is the window definition. The window is titled
  85. "Tutorial 2" and its elements will be laid out verticaly (v). It has a
  86. closegadget (cg) , depthgadget (dg) , and dragbar (db). It will have spaces
  87. inbetween its gadgets (si). It will open on the topleft (tl) of the screen
  88. becoming active (a) when opened. */
  89.  
  90. call topipe(' "Tutorial 2" v cg dg db si a tl')
  91.  
  92. /* define the gadgets*/
  93.  
  94. call topipe(' layout b 0 v')
  95.  
  96. /* Labels are used to tell the user what information to enter in each gadget.
  97. These labels are unatached (ua) when they are defined so don't go directly
  98. into the GUI. Instead they are attached to the following gadget by the
  99. childlabel (chl) keyword. */
  100.  
  101. call topipe(' label gt "Name: " ua')
  102. namegad=topipe('string chl')
  103.  
  104. call topipe(' label gt "Age: " ua')
  105. agegad=topipe('integer chl minn 5 maxn 115 arrows defn 30  weiw 0')
  106.  
  107. call topipe(' label gt "Sex: " ua')
  108. sexgad=topipe('radiobutton rl "Male|Female" chl')
  109.  
  110. call topipe(' label gt "Knowledge: " ua')
  111. knogad=topipe('chooser pu cl "Novice|Average|Good|Expert" chl')
  112.  
  113. call topipe(' label gt "Language(s): " ua')
  114.  
  115. call topipe(' layout b 0 chl')
  116. basgad=topipe('checkbox gt "Basic " chl')
  117. aregad=topipe('checkbox gt "Arexx " chl')
  118. cgad=topipe('checkbox gt "C " chl')
  119. asmgad=topipe('checkbox gt "ASM " chl')
  120. call topipe(' le')
  121.  
  122. call topipe(' le')
  123.  
  124. call topipe(' layout si so')
  125. resgad= topipe('button gt "Reset Form" c')
  126. dongad= topipe('button gt "Done" c')
  127. cangad= topipe('button gt "Cancel" c')
  128. call topipe(' le')
  129.  
  130.  
  131. call topipe(' menu gt "Project  |About|$!   Tutorial 2   |$!  AWNPipe: Example"')
  132. call topipe(' menu gt "Data|@AShow all data|Show part|$@PPersonal|$@SSkill"')
  133.  
  134.  
  135.  
  136. /*open the GUI window*/
  137. call topipe("open")
  138. return
  139.  
  140. printdata:
  141. /*show the value of all the gadgets*/
  142. say '     Name: 'name
  143. say '      Age: 'age
  144. say '      Sex: 'sex
  145. say 'Knowledge: 'knowledge
  146. if basic=1 then say '           Basic'
  147. if arexx=1 then say '           Arexx'
  148. if c=1 then     say '           C'
  149. if asm=1 then   say '           Asm'
  150. return
  151.  
  152. topipe:
  153. /* this routine does error checking on lines written to pipe.*/
  154.  
  155. /*get line to output*/
  156. parse arg out
  157.  
  158. /* write to the pipe*/
  159. call writeln(ca,out)
  160.  
  161. /*get responce and parse it.*/
  162. res=readln(ca)
  163. parse var res res1 res2 .
  164.  
  165. /* if all is ok return the second part of the responce (usualy the GID)*/
  166. if res1='ok' then return(res2)
  167.  
  168. /* something went wrong, we notify the user then exit */
  169. /*show problem line and responce (reponce may be just a blank line)*/
  170. say 'error from: 'out
  171. say '  responce: ' in
  172. exit
  173.